//
//  XLHTTPSessionManager+TaskLevel.m
//  XiangLove
//
//  Created by feng song on 2018/3/29.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLHTTPSessionManager+TaskLevel.h"
#import "XLAccountManager.h"
#import "XLTalkModel.h"
#import "XLApplyInforModel.h"
#import "XLTuijianBannnerListModel.h"
#import <ReactiveCocoa.h>

@implementation XLHTTPSessionManager (TaskLevel)

- (RACSignal *)getUserTaskListUserId {
    NSString *URLString = @"/api/v1/UserTask/GetUserTaskList";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:[[XLAccountManager shareInstance] model].Id forKey:@"userId"];
    return [self GET:URLString parameters:parameters resultClass:[XLTalkModel class]];
}

- (RACSignal *)getUserTaskGetRewardUserID:(NSString *)userId taskID:(NSString *)taskId progressID:(NSString *)progressId {
    NSString *URLString = @"/api/v1/UserTask/GetReward";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:userId ?:@""          forKey:@"userId"];
    [parameters setObject:taskId ?:@""          forKey:@"taskId"];
    [parameters setObject:progressId ?:@""      forKey:@"progressId"];
    
    [self.requestSerializer setValue:[[XLAccountManager shareInstance] model].SecretKey forHTTPHeaderField:@"sign"];
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        NSURLSessionDataTask * task = [self GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
        
    }];
}
#pragma mark - 提交主播的审核信息
- (RACSignal *)SubmitAnchorInfoWithUserId:(NSString *)userId dic:(NSDictionary *)dic{
    NSString *URLString = @"Api/v2/UserInfo/SubmitAnchorInfo";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithDictionary:dic];
    [parameters setObject:userId               ?: @""     forKey:@"userid"];
    [parameters setObject:QudaoName    forKey:@"qudao"];
    [self.requestSerializer setValue:[[XLAccountManager shareInstance] model].SecretKey forHTTPHeaderField:@"sign"];
    return [self XLV2POST:URLString parameters:parameters resultClass:[XLApplyInforModel class]];
}

#pragma mark - 获取主播的审核信息
- (RACSignal *)getGetAuditAnchorInfoWithUserId:(NSString *)userId{
    NSString *URLString = @"/Api/v1/UserInfo/GetAuditAnchorInfo";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:userId ?: @""     forKey:@"userid"];
    [parameters setObject:QudaoName    forKey:@"qudao"];
    [self.requestSerializer setValue:[[XLAccountManager shareInstance] model].SecretKey forHTTPHeaderField:@"sign"];
    return [self GET:URLString parameters:parameters resultClass:[XLApplyInforModel class]];
}

-(RACSignal *)getUserInfoSubmitVideo:(NSString *)userid andVideoUrl:(NSString *)videoUrl
{
    NSString *URLString = @"Api/v1/UserInfo/SubmitVideo";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:userid   ?: @""     forKey:@"userid"];
    [parameters setObject:videoUrl ?: @""     forKey:@"videoUrl"];
    [parameters setObject:QudaoName       forKey:@"qudao"];
    [self.requestSerializer setValue:[[XLAccountManager shareInstance] model].SecretKey forHTTPHeaderField:@"sign"];
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        NSURLSessionDataTask *task = [self POST:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
    }];
    
    
}
- (RACSignal *)downloadUserBannnerList{
    NSString *URLString = @"/api/v1/banner/getbanner";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:[[XLAccountManager shareInstance] model].Id forKey:@"userId"];
    
    [self.requestSerializer setValue:[[XLAccountManager shareInstance] model].SecretKey forHTTPHeaderField:@"sign"];
    return [self GET:URLString parameters:parameters resultClass:[XLTuijianBannnerListModel class]];
}
@end
